<template>
    <el-row>
        <el-col :span="8" :offset="16" style="text-align:right;">
            <el-badge :value="2" type="warning" class="my-msg">
                <el-button size="small">消息</el-button>
            </el-badge>
            <el-dropdown>
                <!-- 修复头像绑定路径 -->
                <el-avatar :size="50" style="margin-top: 5px;" :src="userStore.userInfo.avatar || '默认头像路径'"></el-avatar>
                <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item @click="logout">注销</el-dropdown-item>
                </el-dropdown-menu>
            </el-dropdown>
        </el-col>
    </el-row>
</template>

<script setup>
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { useUserStore } from '@/store' // 导入用户Store

// 正确获取Pinia Store实例
const userStore = useUserStore()
const router = useRouter()

// 修复注销方法：使用Pinia的actions
const logout = () => {
    userStore.logout() // 调用Store中的logout方法
    ElMessage.success("注销成功")
    router.push({ path: "/login" })
}
</script>

<style>
.my-msg {
    margin-top: 30px;
    margin-right: 20px;
}
</style>